namespace ThingsGateway.Foundation
{
    public class EventArgsBase : EventArgs
    {
        /// <summary>
        /// 是否允许操作
        /// </summary>
        public bool IsPermitOperation
        {
            get => Operation.HasFlag(Operation.Permit);
            set
            {
                if (value)
                {
                    AddOperation(Operation.Permit);
                }
                else
                {
                    RemoveOperation(Operation.Permit);
                }
            }
        }

        /// <summary>
        /// 是否已处理
        /// </summary>
        public bool Handled
        {
            get => Operation.HasFlag(Operation.Handled);
            set
            {
                if (value)
                {
                    AddOperation(Operation.Handled);
                }
                else
                {
                    RemoveOperation(Operation.Handled);
                }
            }
        }

        /// <summary>
        /// 操作类型。
        /// </summary>
        public Operation Operation { get; private set; }

        /// <summary>
        /// 添加操作
        /// </summary>
        /// <param name="operation"></param>
        public void AddOperation(Operation operation)
        {
            Operation |= operation;
        }

        /// <summary>
        /// 移除操作
        /// </summary>
        /// <param name="operation"></param>
        public void RemoveOperation(Operation operation)
        {
            if (Operation.HasFlag(operation))
            {
                Operation ^= operation;
            }
        }
    }
}